package com.heima.bos.web.action.impl;


import java.util.List;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.heima.bos.domain.Staff;
import com.heima.bos.service.BaseService;
import com.heima.bos.service.StaffService;
import com.heima.bos.web.action.StaffActionInter;

/**
 * StaffAction
 * @author Administrator
 *
 */
@Controller
@Scope("prototype")
public class StaffAction extends BaseAction<Staff> implements StaffActionInter {
	
	@Resource
	private StaffService staffService;
	@Override
	protected BaseService<Staff> getService() {
		return staffService;
	}
	/**
	 * 分页查询
	 */
	public String pageQuery(){
		pageList();
		String[] excludes = new String[]{"page","pageSize","detachedCriteria","decidezones"};
		writePageBean2Json(pageBean, excludes);
		return NONE;
	}
	/**
	 * 批量作废取派员
	 */
//	@RequiresPermissions("staff-delete")
	public String batchCancel(){
		
		String ids = ServletActionContext.getRequest().getParameter("ids");
		staffService.batchCancel(ids);
		return "cancelSuccess";
	}
	/**
	 * 为添加定区下拉框提供数据
	 */
	public String toDecidezoneSelect(){
		
		DetachedCriteria detachedCriteria = pageBean.getDetachedCriteria();
		detachedCriteria.add(Restrictions.eq("deltag", "0"));
		detachedCriteria.add(Restrictions.isEmpty("decidezones"));
		List<Staff> list = staffService.findByCriteria(detachedCriteria);
		String[] excludes = new String[]{"station","decidezones","telephone","deltag","haspda","standard"};
		writeList2Json(list, excludes);	
		return NONE;
	}
	
	/**
	 * 测试持久化对象
	 */
	public String test(){
		
		staffService.test(entity);
		/*String id = entity.getId();
		Staff staff = staffService.findById(id);
		staff.setName(entity.getName());
		staff.setTelephone(entity.getTelephone());
		staff.setStation(entity.getStation());
		staff.setHaspda(entity.getHaspda());
		staff.setDeltag(entity.getDeltag());
		staff.setStandard(entity.getStandard());*/
		return "updateSuccess";
	}
}
